package org.example.ruoxing_admin_springboot3.exceptionHandleUtils;

import jakarta.annotation.Resource;
import org.example.ruoxing_admin_springboot3.dao.ExceptionInfoDao;
import org.example.ruoxing_admin_springboot3.mapper.ExceptionInfoMapper;
import org.example.ruoxing_admin_springboot3.utils.TimestampUtil;
import org.example.ruoxing_admin_springboot3.utils.UUIDUtil;

import java.util.Arrays;

/**
 * @description 异常处理采集类
 * @author 莫若省
 * @createTime 2024/5/13
*/
public class ExceptionHandleUtils {
    @Resource
    private static ExceptionInfoMapper exceptionInfoMapper;
    /**
     * @description 上报异常信息
     * @author 莫若省
     * @createTime 2024/5/13
    */
    public static void reportException(Exception exception,String exceptionRemark) {
        ExceptionInfoDao exceptionInfoDao = new ExceptionInfoDao();
        exceptionInfoDao.setExceptionId(UUIDUtil.generateUpperCaseUUID());
        exceptionInfoDao.setExceptionMessage(exception.getMessage());
        exceptionInfoDao.setExceptionStack(Arrays.toString(exception.getStackTrace()));
        exceptionInfoDao.setExceptionClass(exception.getClass().getName());
        exceptionInfoDao.setExceptionRemark(exceptionRemark);
        exceptionInfoDao.setCreateTime(TimestampUtil.getCurrentMillisTimestamp());
        exceptionInfoMapper.insertExceptionInfo(exceptionInfoDao);
    }

}
